/**
 * @description 分页参数
 */
export const maxPageParams = {
  offset: 0,
  limit: 0
}

/**
 * 页码减一
 * @param pagination 分页数据
 * @param data data数据源
 * @param selected 选中数据(多选时使用)
 */
export function decPageByData(
  pagination: PaginationState,
  data: RefSource<any[]>,
  selected?: RefSource<any[]>
) {
  const isLastPage = pagination.page * pagination.limit >= pagination.total
  if (!isLastPage) return
  data = getSource(data)
  const page = pagination.page
  const dataLength = data.value.length
  const selectedLength = selected ? getSource(selected).value.length ?? 1 : 1
  const condition = page > 1 && selectedLength === dataLength
  if (condition) pagination.page--
}
